package com.huahua.config;

import com.huahua.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.objenesis.instantiator.perc.PercInstantiator;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author zzuli_huahua
 * @version 1.0
 * @date 2021/6/4 21:11
 */
@Configuration
public class userConfig {

    private UserMapper userMapper;

    @Before
    @Bean
    public void before() throws IOException {

        InputStream resourceAsStream = Resources.getResourceAsStream("mybatisConfig.xml");//扫描数据源的xml文件
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession(true);
        userMapper = sqlSession.getMapper(UserMapper.class);
    }
}
